import Axios from 'axios';
import Qs from 'qs';
Axios.create({
  timeout: 50 * 1000
});
// 字符串参数请求啊
export const AxiosApi = (url, data = {}, type = 'post', param = {}) => {
  return new Promise((resolve, reject) => {
    Axios({
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      },
      transformRequest: [
        (data) => {
          data = Qs.stringify(data);
          return data;
        }
      ],
      method: type,
      url: url,
      data: data,
      params: param
    })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
      });
  });
};
// json参数请求
export const AxiosJsonApi = (url, data = {}, type = 'post', param = {}) => {
  return new Promise((resolve, reject) => {
    Axios({
      headers: {
        'Content-Type': 'application/json'
      },
      transformRequest: [
        (data) => {
          data = JSON.stringify(data);
          return data;
        }
      ],
      method: type,
      url: url,
      data: data,
      params: param
    })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
      });
  });
};
